<template>
	<view class="">
		<view class="cu-modal" :class="[show?'show':'']" >
	
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择登录所属部门</view>
					<!-- <view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view> -->
				</view>
				<view >
				<radio-group class="block" @change="RadioChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in list" :key="item.id" >
							<label class="flex justify-between align-center flex-sub">
								<view class="flex-sub">{{item.departName}}</view>
								<radio class="round blue" :class="radio=='' + item.orgCode?'checked':''"  :checked="radio=='' + item.orgCode?true:false"
								 :value="item.orgCode" ></radio>
							</label>
						</view>
					</view>
				</radio-group>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn bg-blue margin-left" @click="selectdeparts">确定</button>
			
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

	
<script>
	import {
		Base64
	} from '../../static/base64.js'
	import {loginDepart,login}  from '../../api/service.js'
	import ls from '../../utils/local.js'
	export default{
	   data(){
		  return {
			  show:false,
			  list:[],
			  radio:null,
			  userName:'',
			  userNo:''
		  } 
		   },
		   methods:{
			   showModal(data,name){
				 this.show=true;
				 var _this=this;
				this.$nextTick(()=>{
					_this.list=data;
					this.radio=name.orgCode;
					this.userNo=name.username;
				})
				   
			   },
			  hideModal(){
				  this.show=false;
				  this.radio=null
			  },
			  RadioChange(e){
				  console.log(e)
				  this.radio=e.detail.value;
				  var newList=this.list.filter(item=>{
					  return item.orgCode==this.radio;
				  })
				  this.userNo=newList[0].auxUserName;
				  ls.set('departs',newList[0].departName)
			  },
			  selectdeparts(){
				  console.log(this.radio)
				  if(this.radio==null){
					  console.log(35)
					  uni.showToast({
					  	title:"请选择部门",
						duration:1200
					  });
					  return;
				  }else{
            let userNo = this.userNo
					login({'userNo':this.userNo}).then(res=>{
						  if(res.success){
							  ls.set('mUserInfo', res.result.userInfo);
							  ls.set('mToken', res.result.token);
							  // ls.set('Listdeparts',res.result.departs)
							  if(res.result.multi_depart>=1){
                  res.result.departs.forEach(function(item) {
                    if(userNo == item.auxUserName){
                      ls.set('departs',item.departName)
                    }

                  });

							  }else{
							  	ls.set('departs','暂无')
							  }
							  uni.showToast({
							  	title: '欢迎登录成功！',
							  	duration: 1300,
							  	success:function(){
							  	// _this.status=false
							  	uni.navigateTo({
							  	url:'../index/index'
							  	})	
							  	}
							  });
						  }
					  })
						  
				  }
			  }
		   }
	}
</script>

<style lang="scss">
	.content{
		line-height: 60rpx;
		background: #fff;
	}
	uni-toast{
		z-index: 1500!important;
	}
</style>
